package com.philips.work.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.philips.work.domain.YwFlow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.philips.common.log.annotation.Log;
import com.philips.common.log.enums.BusinessType;
import com.philips.common.security.annotation.RequiresPermissions;
import com.philips.work.domain.YwStorMoney;
import com.philips.work.service.IYwStorMoneyService;
import com.philips.common.core.web.controller.BaseController;
import com.philips.common.core.web.domain.AjaxResult;
import com.philips.common.core.utils.poi.ExcelUtil;
import com.philips.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 入库金额Controller
 * 
 * @author philips
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/money")
public class YwStorMoneyController extends BaseController
{
    @Autowired
    private IYwStorMoneyService ywStorMoneyService;

    /**
     * 查询入库金额列表
     */
    @RequiresPermissions("work:money:list")
    @GetMapping("/list")
    public TableDataInfo list(YwStorMoney ywStorMoney)
    {
        startPage();
        List<YwStorMoney> list = ywStorMoneyService.selectYwStorMoneyList(ywStorMoney);
        return getDataTable(list);
    }

    /**
     * 导出入库金额列表
     */
    @RequiresPermissions("work:money:export")
    @Log(title = "入库金额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwStorMoney ywStorMoney)
    {
        List<YwStorMoney> list = ywStorMoneyService.selectYwStorMoneyList(ywStorMoney);
        ExcelUtil<YwStorMoney> util = new ExcelUtil<YwStorMoney>(YwStorMoney.class);
        util.exportExcel(response, list, "入库金额数据");
    }

    /**
     * 获取入库金额详细信息
     */
    @RequiresPermissions("work:money:query")
    @GetMapping(value = "/{ids}")
    public AjaxResult getInfo(@PathVariable("ids") Long ids)
    {
        return success(ywStorMoneyService.selectYwStorMoneyByIds(ids));
    }

    /**
     * 新增入库金额
     */
    @RequiresPermissions("work:money:add")
    @Log(title = "入库金额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwStorMoney ywStorMoney)
    {
        return toAjax(ywStorMoneyService.insertYwStorMoney(ywStorMoney));
    }

    /**
     * 修改入库金额
     */
    @RequiresPermissions("work:money:edit")
    @Log(title = "入库金额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwStorMoney ywStorMoney)
    {
        return toAjax(ywStorMoneyService.updateYwStorMoney(ywStorMoney));
    }

    /**
     * 删除入库金额
     */
    @RequiresPermissions("work:money:remove")
    @Log(title = "入库金额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idss}")
    public AjaxResult remove(@PathVariable Long[] idss)
    {
        return toAjax(ywStorMoneyService.deleteYwStorMoneyByIdss(idss));
    }

    /**
     * 导入总流水合计列表
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YwStorMoney> util = new ExcelUtil<YwStorMoney>(YwStorMoney.class);
        List<YwStorMoney> storMoneyList = util.importExcel(file.getInputStream());
        String message = ywStorMoneyService.importStorMoney(storMoneyList, updateSupport);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<YwStorMoney> util = new ExcelUtil<YwStorMoney>(YwStorMoney.class);
        util.importTemplateExcel(response, "入库金额数据");
    }
}
